import { ErrorMsgEnum } from "@/enums/httpEnum";
import { messageError } from "@/utils/message";

export const showHttpErrorMessage = (err: any) => {
    let message = "请求失败";
    switch (err.status) {
        case 400:
            message = ErrorMsgEnum.ERROR_400;
            break;
        case 401:
            message = ErrorMsgEnum.ERROR_401;
            break;
        case 403:
            message = ErrorMsgEnum.ERROR_403;
            break;
        case 404:
            message = ErrorMsgEnum.ERROR_404;
            break;
        case 500:
            message = ErrorMsgEnum.ERROR_500;
            break;
        case 502:
            message = ErrorMsgEnum.ERROR_502;
            break;
        case 503:
            message = ErrorMsgEnum.ERROR_503;
            break;
        case 504:
            message = ErrorMsgEnum.ERROR_504;
            break;
    }
    messageError(message);
};

export const showErrorMessage = (data: any) => {
    let message = data?.msg || data || "";
    messageError(message);
};
